﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;

namespace Pilot.NET
{

    class Program
    {
        protected static readonly log4net.ILog log = log4net.LogManager.GetLogger("test");

        static void Initialize()
        {
            log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo("Pilot.NET.log4net.xml"));
        }

        static void test_Stream()
        {
            MemoryStream s = new MemoryStream();
            MemoryStream ms2 = new MemoryStream();
            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            byte[] wbuffer, rbuffer;
            string msg;

            // write 10 bytes
            wbuffer = encoding.GetBytes("1234567890");
            s.Write(wbuffer, 0, wbuffer.Length);

            // read 5 bytes
            rbuffer = new byte[1024];
            s.Read(rbuffer, 0, 5);
            msg = encoding.GetString(rbuffer, 0, 5);

            // write 10 bytes
            wbuffer = encoding.GetBytes("abcdefghij");
            s.Write(wbuffer, 0, wbuffer.Length);

            rbuffer = s.GetBuffer();
            msg = encoding.GetString(rbuffer, 0, (int)s.Length);

            log.InfoFormat("{0}", msg);
        }

        static void Main(string[] args)
        {
            Initialize();
            log.Info("-----------------------------------------------");
            // Pilot.NET.Protobuf.protobuf_csharp.test();

            //test_Stream();
            {
                log.Info(System.Configuration.ConfigurationManager.AppSettings["IP"]);
                log.Info(System.Configuration.ConfigurationManager.AppSettings["port"]);
            }

            if (true)
            {
                //Test_GC.test(log);
            }

            /*
            {
                DateTime tmDateTime = DateTime.Now;
                Int64 tmInt64 = tmDateTime.ToBinary();
                log.InfoFormat("tmDateTime={0}, tmInt64={1}", tmDateTime.ToString(), tmInt64);

                DateTime tmDateTime2 = new DateTime();
                DateTime tmDateTime3 = DateTime.FromBinary(tmInt64);
                log.InfoFormat("tmDateTime2={0}, tmDateTime3={1}", tmDateTime2.ToString(), tmDateTime3.ToString());
            }
             * */

            Console.WriteLine("\nPress \"ESC\" key to exit...");
            while (ConsoleKey.Escape != Console.ReadKey(true).Key)
            {
                //
            }
            log.Info("-----------------------------------------------");

        }
    }
}
